import 'package:elephant_fish/http/core/hi_net.dart';
import 'package:elephant_fish/http/request/base_request.dart';
import 'package:elephant_fish/http/request/get_title_request.dart';
import 'package:elephant_fish/http/request/user_upgrade_request.dart';
import 'package:elephant_fish/model/user_info_entity.dart';
import 'package:elephant_fish/model/user_level_entity.dart';
import 'package:elephant_fish/util/TxUtils.dart';
import 'package:elephant_fish/util/size_util.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/painting.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
import 'package:shared_preferences/shared_preferences.dart';

import 'login_page.dart';

class MyLevelPage extends StatefulWidget {
  final UserInfoEntity userInfoEntity;

  const MyLevelPage({Key key, this.userInfoEntity}) : super(key: key);

  @override
  _MyLevelPageState createState() => _MyLevelPageState();
}

class _MyLevelPageState extends State<MyLevelPage> {
  ScrollController _scrollController = ScrollController();
  List<Widget> titleList = List();
  List<Widget> titleList1 = List();
  List<Widget> titleList2 = List();
  List<Widget> titleList3 = List();
  double levelNum = 0.3;
  UserLevelEntity userLevelEntity;
  int titleLevel = 0;
  bool isAnchor = false;
  String userTitle = null;
  String anchorTitle = null;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getTitleList();
    getUserLevel();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Color(0xff140c3d),
      appBar: AppBar(
        backgroundColor: Color(0xff140c3d),
        centerTitle: true,
        leading: GestureDetector(
          child: Icon(
            Icons.arrow_back_ios,
            size: SizeUtil.px(32),
            color: Color(0xffffffff),
          ),
          onTap: () {
            Navigator.pop(context);
          },
        ),
        title: Text(
          '我的等级',
          style: TextStyle(fontSize: SizeUtil.px(32), color: Color(0xffffffff)),
        ),
      ),
      body: Stack(
        children: [
          Align(
            alignment: Alignment.topLeft,
            child: Container(
              width: double.infinity,
              height: SizeUtil.px(469),
              decoration: BoxDecoration(
                borderRadius: BorderRadius.only(
                    bottomRight: Radius.circular(SizeUtil.px(30)),
                    bottomLeft: Radius.circular(SizeUtil.px(30))),
                gradient: LinearGradient(
                    begin: Alignment.topCenter,
                    end: Alignment.bottomCenter,
                    colors: _currentSelectIndex == 0
                        ? [
                            Color(0xfff8d36e),
                            Color(0xffe9b524),
                            Color(0xffe57119),
                          ]
                        : [
                            Color(0xfffe4e7d),
                            Color(0xffff215d),
                            Color(0xffd20e44),
                          ]),
              ),
              child: Column(
                children: [
                  Align(
                      alignment: Alignment.topCenter,
                      child: Padding(
                        padding: EdgeInsets.only(top: SizeUtil.px(26)),
                        child: Container(
                          decoration: BoxDecoration(
                            color: Color(0x200c0c0c),
                            borderRadius: BorderRadius.all(
                                Radius.circular(SizeUtil.px(19))),
                          ),
                          child: Row(
                            mainAxisSize: MainAxisSize.min,
                            children: _getTabs(),
                          ),
                        ),
                      )),
                  Align(
                    alignment: Alignment.topCenter,
                    child: Padding(
                        padding: EdgeInsets.only(top: SizeUtil.px(39)),
                        child: Container(
                          width: SizeUtil.px(139),
                          height: SizeUtil.px(139),
                          child: CircleAvatar(
                            backgroundImage: NetworkImage(
                                'http://119.28.131.94:82' +
                                    widget.userInfoEntity.avatar),
                          ),
                        )),
                  ),
                  SizedBox(height: 10,),
                  _currentSelectIndex == 0 ?
                      Container(width: 0,height: 0,) :
                  _currentSelectIndex== 1 ?
                  Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      userTitle == '平民' ?
                      Image.asset('assets/images/title_pingmin.png',height: 25,)
                          :userTitle == '子爵' ?
                      Image.asset('assets/images/title_zijue.png',height: 25)
                          :userTitle == '伯爵' ?
                      Image.asset('assets/images/title_bojue.png',height: 25)
                          :userTitle == '亲王' ?
                      Image.asset('assets/images/title_qingwang.png',height: 25)
                          :userTitle == '皇帝' ?
                      Image.asset('assets/images/title_huangdi.png',height: 25)
                          :userTitle == '神' ?
                      Image.asset('assets/images/title_shen.png',height: 25)
                          :userTitle == '大帝' ?
                      Image.asset('assets/images/title_dadi.png',height: 25)
                          :userTitle == '天君' ?
                      Image.asset('assets/images/title_tianjun.png',height: 25)
                       :
                      Image.asset('assets/images/title_zaowuzhu.png',height: 25)
                      ,
                      SizedBox(width: 10,),
                      Text(userTitle,style: TextStyle(color: Color(0xfff3f3f3),fontSize: 16),)
                    ],
                  ) :
                  Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      anchorTitle == null ? Container(width: 0,height: 0,) : anchorTitle == '常在'?
                      Image.asset('assets/images/title_changzai.png',height: 30)
                          : anchorTitle == '良人'?
                      Image.asset('assets/images/title_liangren.png',height: 30)
                          : anchorTitle == '贵嫔'?
                      Image.asset('assets/images/title_guipin.png',height: 30)
                          : anchorTitle == '贵妃'?
                      Image.asset('assets/images/title_guifei.png',height: 30)
                          : anchorTitle == '皇后'?
                      Image.asset('assets/images/title_huanghou.png',height: 30)
                          : anchorTitle == '神女'?
                      Image.asset('assets/images/title_shennv.png',height: 30)
                          : anchorTitle == '帝后'?
                      Image.asset('assets/images/title_dihou.png',height: 30)
                          : anchorTitle == '天君夫人'?
                      Image.asset('assets/images/title_tianjunfuren.png',height: 30)
                          :
                      Image.asset('assets/images/title_nvwa.png',height: 30)
                      ,
                      SizedBox(width: 10,),
                      Text(anchorTitle == null ? '' : anchorTitle,style: TextStyle(color: Color(0xfff3f3f3),fontSize: 16),)
                    ],
                  ),
                  Align(
                    alignment: Alignment.topCenter,
                    child: Padding(
                        padding: EdgeInsets.only(top: SizeUtil.px(30)),
                        child: Container(
                          width: SizeUtil.px(585),
                          height: SizeUtil.px(8),
                          decoration: BoxDecoration(
                              borderRadius: BorderRadius.all(
                                  Radius.circular(SizeUtil.px(10)))),
                          child: SizedBox(
                            //限制进度条的高度
                            height: SizeUtil.px(8),
                            //限制进度条的宽度
                            width: SizeUtil.px(585),
                            child: LinearProgressIndicator(
                                //0~1的浮点数，用来表示进度多少;如果 value 为 null 或空，则显示一个动画，否则显示一个定值
                                value: _currentSelectIndex == 0 ? levelNum : _currentSelectIndex == 1 ? 0.8 : 0.8,
                                //背景颜色
                                backgroundColor: Color(0x72ffffff),
                                //进度颜色
                                valueColor: AlwaysStoppedAnimation<Color>(
                                    Color(0xffffffff))),
                          ),
                        )),
                  ),
                  Padding(
                      padding: EdgeInsets.only(top: SizeUtil.px(11)),
                      child: Row(
                        children: [
                          Align(
                              alignment: Alignment.topLeft,
                              child: Padding(
                                padding: EdgeInsets.only(left: SizeUtil.px(91)),
                                child: Text(
                                    _currentSelectIndex !=0 ? '' :  userLevelEntity != null ?'当前：LV.' + userLevelEntity.level.level.toString() : '当前：LV.0',
                                  style: TextStyle(
                                      fontSize: SizeUtil.px(13),
                                      color: Color(0xffe1e1e1)),
                                ),
                              )),
                          Align(
                              alignment: Alignment.topRight,
                              child: Padding(
                                padding:
                                    EdgeInsets.only(left: SizeUtil.px(443)),
                                child: Text(
                                    _currentSelectIndex ==0  ? userLevelEntity!=null? '更高级别：' +
                                        userLevelEntity.level.difference.toString() : '更高级别：100' :
                                    _currentSelectIndex ==1 ?  userLevelEntity!=null? '更高级别：' +
                                        userLevelEntity.title.difference.toString() : '更高级别：100' :
                                    userLevelEntity!=null? '更高级别：' +
                                        userLevelEntity.anchor.difference.toString() : '更高级别：100'
                                  ,
                                  style: TextStyle(
                                      fontSize: SizeUtil.px(13),
                                      color: Color(0xffe1e1e1)),
                                ),
                              ))
                        ],
                      )),
                ],
              ),
            ),
          ),
          Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: _currentSelectIndex != 0 ? EdgeInsets.only(top: SizeUtil.px(440)) :  EdgeInsets.only(top: SizeUtil.px(380)),
              child: Container(
                width: SizeUtil.px(698),
                height: _currentSelectIndex == 0
                    ? SizeUtil.px(400)
                    :_currentSelectIndex == 1 ?  SizeUtil.px(600) : SizeUtil.px(300),
                decoration: BoxDecoration(
                  borderRadius:
                      BorderRadius.all(Radius.circular(SizeUtil.px(13))),
                  color: Color(0xff2b244d),
                ),
                child: Column(
                  children: [
                    Align(
                      alignment: Alignment.topCenter,
                      child: Padding(
                        padding: EdgeInsets.only(top: SizeUtil.px(42)),
                        child: Text(
                          '等级特权',
                          style: TextStyle(
                              color: Color(0xffffffff),
                              fontSize: SizeUtil.px(28)),
                        ),
                      ),
                    ),
                    Expanded(
                        child: _currentSelectIndex == 1
                            ? StaggeredGridView.countBuilder(
                                shrinkWrap: true,
                                controller: _scrollController,
                                physics: const AlwaysScrollableScrollPhysics(),
                                padding:
                                    EdgeInsets.only(left: 3, right: 3, top: 3),
                                crossAxisCount: 3,
                                crossAxisSpacing: 2,
                                mainAxisSpacing: 3,
                                itemCount:  titleList3.length,
                                itemBuilder: (BuildContext context, int index) {
                                  //有banner时第一个item位置显示banner
                                  return _currentSelectIndex == 1
                                      ? titleList3[index]
                                      : titleList1[index];
                                },
                                staggeredTileBuilder: (int index) {
                                  return StaggeredTile.fit(1);
                                })
                            : _currentSelectIndex == 2
                                ? isAnchor
                                    ? StaggeredGridView.countBuilder(
                                        shrinkWrap: true,
                                        controller: _scrollController,
                                        physics:
                                            const AlwaysScrollableScrollPhysics(),
                                        padding: EdgeInsets.only(
                                            left: 3, right: 3, top: 3),
                                        crossAxisCount: 3,
                                        crossAxisSpacing: 2,
                                        mainAxisSpacing: 3,
                                        itemCount: _currentSelectIndex == 1
                                            ? titleLevel
                                            : titleList1.length,
                                        itemBuilder:
                                            (BuildContext context, int index) {
                                          //有banner时第一个item位置显示banner
                                          return _currentSelectIndex == 1
                                              ? titleList[index]
                                              : titleList1[index];
                                        },
                                        staggeredTileBuilder: (int index) {
                                          return StaggeredTile.fit(1);
                                        })
                                    : Center(
                                        child: Text(
                                          '您还不是主播',
                                          style: TextStyle(
                                              color: Color(0xfff3f3f3)),
                                        ),
                                      )
                                : Row(
                                    children: [
                                      Align(
                                        alignment: Alignment.topLeft,
                                        child: Padding(
                                          padding: EdgeInsets.only(
                                              top: SizeUtil.px(120), left: 30),
                                          child: Column(
                                            children: [
                                              Align(
                                                alignment: Alignment.topCenter,
                                                child: Container(
                                                  width: SizeUtil.px(42),
                                                  child: Image.asset(
                                                      'assets/images/level_level.png'),
                                                ),
                                              ),
                                              Align(
                                                alignment: Alignment.topCenter,
                                                child: Padding(
                                                  padding: EdgeInsets.only(
                                                      top: SizeUtil.px(18)),
                                                  child: Text(
                                                    '排名靠前',
                                                    style: TextStyle(
                                                        fontSize:
                                                            SizeUtil.px(26),
                                                        color:
                                                            Color(0xffffffff)),
                                                  ),
                                                ),
                                              ),
                                              Align(
                                                alignment: Alignment.topCenter,
                                                child: Padding(
                                                  padding: EdgeInsets.only(
                                                      top: SizeUtil.px(23)),
                                                  child: Text(
                                                    '房间内排名靠前，彰显尊贵',
                                                    style: TextStyle(
                                                        fontSize:
                                                            SizeUtil.px(19),
                                                        color:
                                                            Color(0xff818181)),
                                                  ),
                                                ),
                                              ),
                                            ],
                                          ),
                                        ),
                                      ),
                                      SizedBox(
                                        width: 50,
                                      ),
                                      Padding(
                                        padding: EdgeInsets.only(
                                            top: SizeUtil.px(120), right: 30),
                                        child: Column(
                                          children: [
                                            Align(
                                              alignment: Alignment.topCenter,
                                              child: Container(
                                                width: SizeUtil.px(42),
                                                child: Image.asset(
                                                    'assets/images/level_money.png'),
                                              ),
                                            ),
                                            Align(
                                              alignment: Alignment.topCenter,
                                              child: Padding(
                                                padding: EdgeInsets.only(
                                                    top: SizeUtil.px(18)),
                                                child: Text(
                                                  '尊贵身份',
                                                  style: TextStyle(
                                                      fontSize: SizeUtil.px(26),
                                                      color: Color(0xffffffff)),
                                                ),
                                              ),
                                            ),
                                            Align(
                                              alignment: Alignment.topCenter,
                                              child: Padding(
                                                padding: EdgeInsets.only(
                                                    top: SizeUtil.px(23)),
                                                child: Text(
                                                  '房间内显示等级，彰显尊贵',
                                                  style: TextStyle(
                                                      fontSize: SizeUtil.px(19),
                                                      color: Color(0xff818181)),
                                                ),
                                              ),
                                            ),
                                          ],
                                        ),
                                      ),
                                    ],
                                  ))
                  ],
                ),
              ),
            ),
          ),
          Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: _currentSelectIndex != 0 ? EdgeInsets.only(top: SizeUtil.px(1060)) :EdgeInsets.only(top: SizeUtil.px(940)),
              child: Column(
                children: [
                  Text(
                    '如何快速提升',
                    style: TextStyle(
                        fontSize: SizeUtil.px(28), color: Color(0xffffffff)),
                  ),
                  SizedBox(
                    height: SizeUtil.px(32),
                  ),
                  _currentSelectIndex == 0
                      ? Image(
                          image:
                              AssetImage('assets/images/level_gift_yellow.png'),
                          width: SizeUtil.px(138),
                        )
                      : Image(
                          image: AssetImage('assets/images/level_gift_red.png'),
                          width: SizeUtil.px(138),
                        ),
                  SizedBox(
                    height: SizeUtil.px(35),
                  ),
                  Text(
                    '送礼物',
                    style: TextStyle(
                        fontSize: SizeUtil.px(28), color: Color(0xffffffff)),
                  ),
                  SizedBox(
                    height: SizeUtil.px(7),
                  ),
                  Text(
                    '送出1金币礼物=1经验值',
                    style: TextStyle(
                        fontSize: SizeUtil.px(17), color: Color(0xff818181)),
                  ),
                ],
              ),
            ),
          )
        ],
      ),
    );
  }

  int _currentSelectIndex = 0;

  List<Widget> _getTabs() {
    List<Widget> tabWidgets = List();
    for (int i = 0; i < 3; i++) {
      tabWidgets.add(new Padding(
        padding: EdgeInsets.only(
            left: _currentSelectIndex == 0
                ? i == 0
                    ? 0
                    : SizeUtil.px(55)
                : _currentSelectIndex == 1
                    ? i == 0
                        ? SizeUtil.px(22)
                        : SizeUtil.px(77)
                    : i == 0
                        ? SizeUtil.px(22)
                        : SizeUtil.px(77),
            right: _currentSelectIndex == 0
                ? SizeUtil.px(22)
                : _currentSelectIndex == 1
                    ? SizeUtil.px(22)
                    : 0,
            bottom: SizeUtil.px(4)),
        child: new GestureDetector(
          onTap: () {
            setState(() {
              _currentSelectIndex = i;
            });
          },
          child: _currentSelectIndex == i
              ? Container(
                  width: SizeUtil.px(159),
                  height: SizeUtil.px(41),
                  decoration: BoxDecoration(
                      color: Color(0x200c0c0c),
                      borderRadius:
                          BorderRadius.all(Radius.circular(SizeUtil.px(19)))),
                  child: Text(
                    i == 0
                        ? "财富等级"
                        : i == 1
                            ? "用户称号"
                            : "主播称号",
                    textAlign: TextAlign.center,
                    style: TextStyle(
                        fontSize: SizeUtil.px(29), color: Color(0xffffffff)),
                  ),
                )
              : Container(
                  child: Text(
                    i == 0
                        ? "财富等级"
                        : i == 1
                            ? "用户称号"
                            : "主播称号",
                    textAlign: TextAlign.center,
                    style: TextStyle(
                        fontSize: SizeUtil.px(29), color: Color(0xffffffff)),
                  ),
                ),
        ),
      ));
    }
    return tabWidgets;
  }

  ///设置用户称号
  void getTitleList() {
    titleList.add(Column(
      children: [
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: 0),
              child: Image.asset(
                'assets/images/title_gold_qian.png',
                width: SizeUtil.px(91),
                height: SizeUtil.px(91),
              ),
            )),
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: SizeUtil.px(10)),
              child: Text(
                '排名靠前',
                style: TextStyle(
                    fontSize: SizeUtil.px(22), color: Color(0xffe5d1b2)),
              ),
            )),
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: SizeUtil.px(2)),
              child: Text(
                '彰显尊贵',
                style: TextStyle(
                    fontSize: SizeUtil.px(20), color: Color(0xff818181)),
              ),
            )),
      ],
    ));
    titleList.add(Column(
      children: [
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: 0),
              child: Image.asset(
                'assets/images/title_gold_xunzhang.png',
                width: SizeUtil.px(91),
                height: SizeUtil.px(91),
              ),
            )),
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: SizeUtil.px(10)),
              child: Text(
                '勋章',
                style: TextStyle(
                    fontSize: SizeUtil.px(22), color: Color(0xffe5d1b2)),
              ),
            )),
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: SizeUtil.px(2)),
              child: Text(
                '专属标识',
                style: TextStyle(
                    fontSize: SizeUtil.px(20), color: Color(0xff818181)),
              ),
            )),
      ],
    ));
    titleList.add(Column(
      children: [
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: 0),
              child: Image.asset(
                'assets/images/title_gold_head.png',
                width: SizeUtil.px(91),
                height: SizeUtil.px(91),
              ),
            )),
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: SizeUtil.px(10)),
              child: Text(
                '仙族头像框',
                style: TextStyle(
                    fontSize: SizeUtil.px(22), color: Color(0xffe5d1b2)),
              ),
            )),
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: SizeUtil.px(2)),
              child: Text(
                '彰显财富',
                style: TextStyle(
                    fontSize: SizeUtil.px(20), color: Color(0xff818181)),
              ),
            )),
      ],
    ));
    titleList.add(Column(
      children: [
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: 0),
              child: Image.asset(
                'assets/images/title_gold_qipao.png',
                width: SizeUtil.px(91),
                height: SizeUtil.px(91),
              ),
            )),
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: SizeUtil.px(10)),
              child: Text(
                '发言气泡',
                style: TextStyle(
                    fontSize: SizeUtil.px(22), color: Color(0xffe5d1b2)),
              ),
            )),
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: SizeUtil.px(2)),
              child: Text(
                '仙气十足',
                style: TextStyle(
                    fontSize: SizeUtil.px(20), color: Color(0xff818181)),
              ),
            )),
      ],
    ));
    titleList.add(Column(
      children: [
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: 0),
              child: Image.asset(
                'assets/images/title_gold_liang.png',
                width: SizeUtil.px(91),
                height: SizeUtil.px(91),
              ),
            )),
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: SizeUtil.px(10)),
              child: Text(
                '可选靓号',
                style: TextStyle(
                    fontSize: SizeUtil.px(22), color: Color(0xffe5d1b2)),
              ),
            )),
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: SizeUtil.px(2)),
              child: Text(
                '靓丽非凡',
                style: TextStyle(
                    fontSize: SizeUtil.px(20), color: Color(0xff818181)),
              ),
            )),
      ],
    ));
    titleList.add(Column(
      children: [
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: 0),
              child: Image.asset(
                'assets/images/title_gold_jin.png',
                width: SizeUtil.px(91),
                height: SizeUtil.px(91),
              ),
            )),
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: SizeUtil.px(10)),
              child: Text(
                '炫酷进场',
                style: TextStyle(
                    fontSize: SizeUtil.px(22), color: Color(0xffe5d1b2)),
              ),
            )),
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: SizeUtil.px(2)),
              child: Text(
                '尊贵非凡',
                style: TextStyle(
                    fontSize: SizeUtil.px(20), color: Color(0xff818181)),
              ),
            )),
      ],
    ));
    titleList.add(Column(
      children: [
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: 0),
              child: Image.asset(
                'assets/images/title_gold_danmu.png',
                width: SizeUtil.px(91),
                height: SizeUtil.px(91),
              ),
            )),
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: SizeUtil.px(10)),
              child: Text(
                '隐榜',
                style: TextStyle(
                    fontSize: SizeUtil.px(22), color: Color(0xffe5d1b2)),
              ),
            )),
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: SizeUtil.px(2)),
              child: Text(
                '彰显尊贵',
                style: TextStyle(
                    fontSize: SizeUtil.px(20), color: Color(0xff818181)),
              ),
            )),
      ],
    ));
    titleList.add(Column(
      children: [
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: 0),
              child: Image.asset(
                'assets/images/title_fangjin_gold.png',
                width: SizeUtil.px(91),
                height: SizeUtil.px(91),
              ),
            )),
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: SizeUtil.px(10)),
              child: Text(
                '防踢防禁言',
                style: TextStyle(
                    fontSize: SizeUtil.px(22), color: Color(0xffe5d1b2)),
              ),
            )),
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: SizeUtil.px(2)),
              child: Text(
                '霸道权利',
                style: TextStyle(
                    fontSize: SizeUtil.px(20), color: Color(0xff818181)),
              ),
            )),
      ],
    ));
    titleList.add(Column(
      children: [
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: 0),
              child: Image.asset(
                'assets/images/title_gold_mingpian.png',
                width: SizeUtil.px(91),
                height: SizeUtil.px(91),
              ),
            )),
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: SizeUtil.px(10)),
              child: Text(
                '隐身',
                style: TextStyle(
                    fontSize: SizeUtil.px(22), color: Color(0xffe5d1b2)),
              ),
            )),
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: SizeUtil.px(2)),
              child: Text(
                '彰显财富',
                style: TextStyle(
                    fontSize: SizeUtil.px(20), color: Color(0xff818181)),
              ),
            )),
      ],
    ));

    titleList1.add(Column(
      children: [
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: 0),
              child: Image.asset(
                'assets/images/title_gold_qian.png',
                width: SizeUtil.px(91),
                height: SizeUtil.px(91),
              ),
            )),
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: SizeUtil.px(10)),
              child: Text(
                '排名靠前',
                style: TextStyle(
                    fontSize: SizeUtil.px(22), color: Color(0xffe5d1b2)),
              ),
            )),
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: SizeUtil.px(2)),
              child: Text(
                '彰显尊贵',
                style: TextStyle(
                    fontSize: SizeUtil.px(20), color: Color(0xff818181)),
              ),
            )),
      ],
    ));
    titleList1.add(Column(
      children: [
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: 0),
              child: Image.asset(
                'assets/images/title_gold_head.png',
                width: SizeUtil.px(91),
                height: SizeUtil.px(91),
              ),
            )),
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: SizeUtil.px(10)),
              child: Text(
                '专属主播图标',
                style: TextStyle(
                    fontSize: SizeUtil.px(22), color: Color(0xffe5d1b2)),
              ),
            )),
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: SizeUtil.px(2)),
              child: Text(
                '彰显人气',
                style: TextStyle(
                    fontSize: SizeUtil.px(20), color: Color(0xff818181)),
              ),
            )),
      ],
    ));
    titleList1.add(Column(
      children: [
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: 0),
              child: Image.asset(
                'assets/images/title_gold_xunzhang.png',
                width: SizeUtil.px(91),
                height: SizeUtil.px(91),
              ),
            )),
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: SizeUtil.px(10)),
              child: Text(
                '专属主播勋章',
                style: TextStyle(
                    fontSize: SizeUtil.px(22), color: Color(0xffe5d1b2)),
              ),
            )),
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: SizeUtil.px(2)),
              child: Text(
                '凹显魅力',
                style: TextStyle(
                    fontSize: SizeUtil.px(20), color: Color(0xff818181)),
              ),
            )),
      ],
    ));

    titleList2.add(Column(
      children: [
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: 0),
              child: Image.asset(
                'assets/images/title_grey_qian.png',
                width: SizeUtil.px(91),
                height: SizeUtil.px(91),
              ),
            )),
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: SizeUtil.px(10)),
              child: Text(
                '排名靠前',
                style: TextStyle(
                    fontSize: SizeUtil.px(22), color: Color(0xffe5d1b2)),
              ),
            )),
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: SizeUtil.px(2)),
              child: Text(
                '彰显尊贵',
                style: TextStyle(
                    fontSize: SizeUtil.px(20), color: Color(0xff818181)),
              ),
            )),
      ],
    ));
    titleList2.add(Column(
      children: [
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: 0),
              child: Image.asset(
                'assets/images/title_grey_xunzhang.png',
                width: SizeUtil.px(91),
                height: SizeUtil.px(91),
              ),
            )),
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: SizeUtil.px(10)),
              child: Text(
                '勋章',
                style: TextStyle(
                    fontSize: SizeUtil.px(22), color: Color(0xffe5d1b2)),
              ),
            )),
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: SizeUtil.px(2)),
              child: Text(
                '专属标识',
                style: TextStyle(
                    fontSize: SizeUtil.px(20), color: Color(0xff818181)),
              ),
            )),
      ],
    ));
    titleList2.add(Column(
      children: [
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: 0),
              child: Image.asset(
                'assets/images/title_grey_head.png',
                width: SizeUtil.px(91),
                height: SizeUtil.px(91),
              ),
            )),
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: SizeUtil.px(10)),
              child: Text(
                '仙族头像框',
                style: TextStyle(
                    fontSize: SizeUtil.px(22), color: Color(0xffe5d1b2)),
              ),
            )),
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: SizeUtil.px(2)),
              child: Text(
                '彰显财富',
                style: TextStyle(
                    fontSize: SizeUtil.px(20), color: Color(0xff818181)),
              ),
            )),
      ],
    ));
    titleList2.add(Column(
      children: [
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: 0),
              child: Image.asset(
                'assets/images/title_grey_qipao.png',
                width: SizeUtil.px(91),
                height: SizeUtil.px(91),
              ),
            )),
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: SizeUtil.px(10)),
              child: Text(
                '发言气泡',
                style: TextStyle(
                    fontSize: SizeUtil.px(22), color: Color(0xffe5d1b2)),
              ),
            )),
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: SizeUtil.px(2)),
              child: Text(
                '仙气十足',
                style: TextStyle(
                    fontSize: SizeUtil.px(20), color: Color(0xff818181)),
              ),
            )),
      ],
    ));
    titleList2.add(Column(
      children: [
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: 0),
              child: Image.asset(
                'assets/images/title_grey_liang.png',
                width: SizeUtil.px(91),
                height: SizeUtil.px(91),
              ),
            )),
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: SizeUtil.px(10)),
              child: Text(
                '可选靓号',
                style: TextStyle(
                    fontSize: SizeUtil.px(22), color: Color(0xffe5d1b2)),
              ),
            )),
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: SizeUtil.px(2)),
              child: Text(
                '靓丽非凡',
                style: TextStyle(
                    fontSize: SizeUtil.px(20), color: Color(0xff818181)),
              ),
            )),
      ],
    ));
    titleList2.add(Column(
      children: [
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: 0),
              child: Image.asset(
                'assets/images/title_grey_jin.png',
                width: SizeUtil.px(91),
                height: SizeUtil.px(91),
              ),
            )),
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: SizeUtil.px(10)),
              child: Text(
                '炫酷进场',
                style: TextStyle(
                    fontSize: SizeUtil.px(22), color: Color(0xffe5d1b2)),
              ),
            )),
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: SizeUtil.px(2)),
              child: Text(
                '尊贵非凡',
                style: TextStyle(
                    fontSize: SizeUtil.px(20), color: Color(0xff818181)),
              ),
            )),
      ],
    ));
    titleList2.add(Column(
      children: [
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: 0),
              child: Image.asset(
                'assets/images/title_grey_danmu.png',
                width: SizeUtil.px(91),
                height: SizeUtil.px(91),
              ),
            )),
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: SizeUtil.px(10)),
              child: Text(
                '隐榜',
                style: TextStyle(
                    fontSize: SizeUtil.px(22), color: Color(0xffe5d1b2)),
              ),
            )),
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: SizeUtil.px(2)),
              child: Text(
                '彰显尊贵',
                style: TextStyle(
                    fontSize: SizeUtil.px(20), color: Color(0xff818181)),
              ),
            )),
      ],
    ));
    titleList2.add(Column(
      children: [
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: 0),
              child: Image.asset(
                'assets/images/title_fangjin.png',
                width: SizeUtil.px(91),
                height: SizeUtil.px(91),
              ),
            )),
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: SizeUtil.px(10)),
              child: Text(
                '防踢防禁言',
                style: TextStyle(
                    fontSize: SizeUtil.px(22), color: Color(0xffe5d1b2)),
              ),
            )),
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: SizeUtil.px(2)),
              child: Text(
                '霸道权利',
                style: TextStyle(
                    fontSize: SizeUtil.px(20), color: Color(0xff818181)),
              ),
            )),
      ],
    ));
    titleList2.add(Column(
      children: [
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: 0),
              child: Image.asset(
                'assets/images/title_grey_mingpian.png',
                width: SizeUtil.px(91),
                height: SizeUtil.px(91),
              ),
            )),
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: SizeUtil.px(10)),
              child: Text(
                '隐身',
                style: TextStyle(
                    fontSize: SizeUtil.px(22), color: Color(0xffe5d1b2)),
              ),
            )),
        Align(
            alignment: Alignment.topCenter,
            child: Padding(
              padding: EdgeInsets.only(top: SizeUtil.px(2)),
              child: Text(
                '彰显财富',
                style: TextStyle(
                    fontSize: SizeUtil.px(20), color: Color(0xff818181)),
              ),
            )),
      ],
    ));
    getUserTitle();

  }

  void getTitleList1() {
    for(int i = 0 ;i < titleLevel;i++){
      titleList3.add(titleList[i]);
    }
    for(int i = titleLevel; i < titleList2.length ; i++){
      titleList3.add(titleList2[i]);
    }
  }

  Future<void> getUserTitle() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    String appToken = prefs.getString('app-token');
    BaseRequest request = GetTitleRequest();
    request.addHeader('usertoken', appToken);
    var result = await HiNet.getInstance().fire(request);
    if (result['code'] == -1) {
      TxUtils.showErrorToast('登录失效，请重新登录', context);
      Navigator.pop(context);
      Navigator.of(context).push(MaterialPageRoute(
        builder: (context) {
          return LoginPage(
            arguments: {'loginCode': '-1'},
          );
        },
      ));
    } else if (result['code'] == 0) {
      setState(() {
        userTitle = result['data']['user_title'];
        anchorTitle = result['data']['anchor_title'];
        switch (userTitle) {
          case '平民':
            titleLevel = 0;
            break;
          case '子爵':
          case '伯爵':
            titleLevel = 3;
            break;
          case '亲王':
          case '皇帝':
          case '神':
            titleLevel = 6;
            break;
          case '大帝':
          case '天君':
            titleLevel = 7;
            break;
          case '造物主':
            titleLevel = 9;
            break;
        }
        if (anchorTitle != null) {
          isAnchor = true;
        } else {
          isAnchor = false;
        }
      });
    }
    getTitleList1();
  }

  getUserLevel() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    String appToken = prefs.getString('app-token');
    BaseRequest request = UserUpgradeRequest();
    request.addHeader('usertoken', appToken);
    var result = await HiNet.getInstance().fire(request);
    if (result['code'] == -1) {
      TxUtils.showErrorToast('登录失效，请重新登录', context);
      Navigator.pop(context);
      Navigator.of(context).push(MaterialPageRoute(
        builder: (context) {
          return LoginPage(
            arguments: {'loginCode': '-1'},
          );
        },
      ));
    }else if(result['code'] == 0){
      setState(() {
        userLevelEntity = UserLevelEntity.fromJson(
            new Map<String, dynamic>.from(result['data']));
        levelNum = userLevelEntity.level.now / (userLevelEntity.level.now + userLevelEntity.level.next);
      });
    }
  }


}
